<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <TITLE>ERP SYSTEM</TITLE>
    <META name="description" content="ERP.COM"/>

    <!-- 引入外部js或css -->
    <script th:src="@{https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js}" type="text/javascript" ></script>

    <!-- 引入内部js或css -->
    <script th:src="${'/lib/layui/layui.js'}" type="text/javascript" charset="utf-8"></script>
    <script th:src="${'/js/xadmin.js'}" type="text/javascript"></script>
    <link th:href="${'/css/font.css'}" rel="stylesheet">
    <link th:href="${'/css/xadmin.css'}" rel="stylesheet">
</head>

<body class="login-bg">
<div class="login" >
    <div class="message">企业资产管理系统-忘记密码</div>
    <font  id="error" size="10" class="text-align:center" color="red"></font>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
        <div class="layui-form-item">
            <label for="account" class="layui-form-label"> <span
                    class="x-red">*</span>账号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="account"
                       name="account" required=""
                       lay-verify="nikename" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="password" class="layui-form-label"> <span
                    class="x-red">*</span>新密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password" name="password" required="" lay-verify="password"
                       autocomplete="off" class="layui-input">
            </div>
            <div id="L_pass" class="layui-form-mid layui-word-aux ">
                至少6个字符</div>
        </div>
        <div name="pwd" class="layui-form-item">
            <label for="L_repass" class="layui-form-label"> <span
                    class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input onchange="confirm()" type="password" id="L_repass"
                       name="repass" autocomplete="off" class="layui-input">
            </div>
            <div id="confire" class="layui-form-mid layui-word-aux ">
                两次密码必须一致</div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label"> </label>
            <button id="resetButton" class="layui-btn" lay-filter="login" lay-submit="">
                确定</button>
            <a class="layui-btn" a href="/login" lay-submit=""> 返回
            </a>
        </div>
    </form>
</div>
</body>

<script>
    //密码输入框事件
    function safePW(){
        if($('#password').val().length>5){
            $("#password").html("<i class=\"layui-icon layui-anim layui-anim-scale \" style=\"color: #1E9FFF;\">&#xe618;</i>")
        }
    };

    //密码确认框事件
    function confirm(){
        if($('#password').val()==$('#L_repass').val()){
            $("#confire").html("<i class=\"layui-icon layui-anim layui-anim-scale \" style=\"color: #1E9FFF;\">&#xe618;</i>")
        }
    };

    // layui.use(['form','layer','laydate','upload'], function(){
    //     $ = layui.jquery;
    //     var form = layui.form,
    //         layer = layui.layer,
    // //验证器
    // form.verify({
    //     pass: [/(.+){6,12}$/, '密码必须6到12位'],
    //     repass: function(value){
    //         if($('#password').val()!=$('#L_repass').val()){
    //             return '两次密码不一致';
    //         }
    //     }
    // });
    // });
    /*
     * 用户密码重置
     */
    $("#resetButton").bind("click", function() {

        var user={};
        user.account = $("[name='account']").val();
        user.password = $("[name='password']").val();
        var layer =layui.layer;
        console.log(user);
        if (user.account.length<2) {
            layer.msg('昵称至少得2个字符啊',{icon: 0});
            return;
        }else if (user.password.length<6||user.password.length>12){
            layer.msg('密码必须6到12位',{icon: 0});
            return;
        }
        $.ajax({
            url : "/doResetPwd",
            type : "POST",
            contentType: "application/json",
            data : JSON.stringify(user),
            success : function (data) {
                if (data.status == 200) {
                    // todo
                    location.href = "/login";
                } else {
                    layer.msg(data.message, {icon: 0});
                }
            },
            error : function (data) {
                layer.msg(data.responseText, {icon: 0});
            }
        });
    });
    // //form提交
    // form.on('submit(add)', function(data){
    //     console.log(data);
    //     $.ajax({
    //         url :"/doResetPwd",
    //         type : "POST",
    //         data : $('#form1').serialize(),
    //         dataType : "text",
    //         success : function(data) {
    //             var result = eval("(" + data + ")");
    //             if (result.status == 200) {
    //                 layer.msg("修改成功",{
    //                     icon : 1,
    //                     time: 500,
    //                 },function () {
    //                     var index = parent.layer.getFrameIndex(window.name);
    //                     parent.location.reload();
    //                     parent.layer.close(index);
    //                 });
    //             } else {
    //                 layer.msg(result.message, {icon: 0});
    //             }
    //         },
    //         error : function() {
    //             layer.msg('无法连接服务器', {icon: 2});
    //         }
    //     });
    //     return false;
    // });


</script>
</html>
